﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Wandering
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
           
            if (MainForm.MyProperty.dataGridView1.SelectedRows.Count == 1)
            {
                var id = MainForm.MyProperty.dataGridView1.SelectedCells[0].Value.ToString();

                if (txtUid.Text == "" && txtPwd.Text != "")
                {
                    string sql = string.Format("update Articles set author='{0}' where id={1}", txtPwd.Text, id);

                    var res = DBHelper.InsertOrDeleteOrUpdate(sql);

                    if (res >= 1)
                    {
                        MessageBox.Show("更新成功");
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("更新失败");
                    }
                }
                else if (txtUid.Text != "" && txtPwd.Text == "")
                {
                    string sql = string.Format("update Articles set Title='{0}' where id={1}", txtUid.Text,id);

                    var res = DBHelper.InsertOrDeleteOrUpdate(sql);

                    if (res >= 1)
                    {
                        MessageBox.Show("更新成功");
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("更新失败");
                    }
                }
                else
                {
                    MessageBox.Show("请添加要更改的内容");
                }
            }
            else
            {
                MessageBox.Show("你没有选中一行,请选中再来");
                this.Close();
            }


        }
    }
}
